package com.sskj.finance.http;

import com.sskj.common.util.MD5Util;
import com.sskj.finance.bean.HomeQbwCoinsList;
import com.lzy.okgo.request.GetRequest;
import com.sskj.finance.bean.AssetBean;
import com.sskj.finance.bean.HomeBorrowTransTotal;
import com.sskj.finance.bean.HomeQbwAccountList;
import com.sskj.finance.bean.HomeLendGetTransrecord;
import com.sskj.finance.bean.HomeLendGetTransrecord;
import com.sskj.finance.bean.HomeLendBlend;
import com.sskj.finance.bean.HomeLendLendCoinListBean;
import com.sskj.finance.bean.HomeBorrowGetTransrecordBean;
import com.sskj.finance.bean.HomeBorrowMortgageInfoBean;
import com.sskj.finance.bean.HomeBorrowBorrowInfoBean;
import com.sskj.finance.bean.RateBean;
import com.sskj.finance.bean.SupplyData;
import com.sskj.finance.bean.TradeAccountBean;
import com.sskj.finance.bean.TransferRecordBean;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.request.PostRequest;
import com.sskj.common.base.HttpData;
import com.sskj.finance.bean.AccountBean;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.util.CommonUtil;

import java.util.List;
import java.util.concurrent.Executor;

/**
 * 作者 :吕志豪
 * 简书：https://www.jianshu.com/u/6e525b929aac
 * github：https://github.com/lvzhihao100
 * 描述：
 * 创建时间：2018-10-15 14:08
 */
public class HttpService {


    /**
     * 理财账户
     *
     * @return
     */
    public PostRequest<HttpData<AccountBean>> financeAccount() {
        return OkGo.<HttpData<AccountBean>>post(HttpConfig.BASE_URL + HttpConfig.FINANCE_ACCOUNT);
    }

    /**
     * 交易、理财账户划转
     *
     * @param type 1交易账户to理财账户 2理财账户to交易账户
     * @param num  充值数量
     * @param tpwd 资金密码
     * @param code 币种标识，如：BTC、ETH
     * @return
     */
    public PostRequest<HttpData> transfer(String type, String num, String tpwd, String code) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.TRANSFER)
                .params("type", type)
                .params("num", num)
                .params("tpwd", CommonUtil.getFiveMd5Value(tpwd))
                .params("code", code);
    }

    /**
     * 划转记录
     *
     * @param page 页码，默认1
     * @param size 页条数，默认10
     * @return
     */
    public PostRequest<HttpData<PageBean<TransferRecordBean>>> transfer_record(String page, String size) {
        return OkGo.<HttpData<PageBean<TransferRecordBean>>>post(HttpConfig.BASE_URL + HttpConfig.TRANSFER_RECORD)
                .params("page", page)
                .params("size", size);
    }

    /**
     * 获取借入币信息
     *
     * @param type     1押币借钱 2押钱借币
     * @param out_code 抵押币种标识，如：BTC ETH USDT
     * @param in_code  借入币种标识，如：BTC ETH USDT
     * @param num      抵押数量
     * @param days     天数
     * @return
     */
    public PostRequest<HttpData<HomeBorrowBorrowInfoBean>> homeBorrowBorrowInfo(String type, String out_code, String in_code, String num, String days) {
        return OkGo.<HttpData<HomeBorrowBorrowInfoBean>>post(HttpConfig.BASE_URL + HttpConfig.HOME_BORROW_BORROW_INFO)
                .params("type", type)
                .params("out_code", out_code)
                .params("in_code", in_code)
                .params("num", num)
                .params("days", days);
    }

    /**
     * 获取抵押币信息
     *
     * @param out_code 抵押币种标识，如：BTC ETH USDT
     * @return
     */
    public PostRequest<HttpData<HomeBorrowMortgageInfoBean>> homeBorrowMortgageInfo(String type, String out_code) {
        return OkGo.<HttpData<HomeBorrowMortgageInfoBean>>post(HttpConfig.BASE_URL + HttpConfig.HOME_BORROW_MORTGAGE_INFO)
                .params("type", type)
                .params("out_code", out_code)
                ;
    }

    /**
     * 抵押借款
     *
     * @param type     1押币借钱 2押钱借币
     * @param out_code 抵押币种标识，如：BTC ETH USDT
     * @param in_code  借入币种标识，如：BTC ETH USDT
     * @param num      抵押数量
     * @param days     天数
     * @param in_num   借款数量
     * @return
     */
    public PostRequest<HttpData> homeBorrowBorrowAdd(String type, String out_code, String in_code, String num, String days, String in_num, String tpwd) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.HOME_BORROW_BORROW_ADD)
                .params("type", type)
                .params("out_code", out_code)
                .params("in_code", in_code)
                .params("num", num)
                .params("days", days)
                .params("tpwd", CommonUtil.getFiveMd5Value(tpwd))
                .params("in_num", in_num);
    }

    /**
     * 还款
     *
     * @param order_id 借贷记录id
     * @return
     */
    public PostRequest<HttpData> homeBorrowPayback(String order_id, String tpwd) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.HOME_BORROW_PAYBACK)
                .params("order_id", order_id)
                .params("tpwd", CommonUtil.getFiveMd5Value(tpwd))
                ;
    }

    /**
     * 抵押记录
     *
     * @param type   1押币借钱 2压钱借币
     * @param status 1计息中 2已赎回
     * @param p      页码，默认1
     * @param size   页条数，默认10
     * @return
     */
    public PostRequest<HttpData<PageBean<HomeBorrowGetTransrecordBean>>> homeBorrowGetTransrecord(String type, String status, String pid, String p, String size) {
        return OkGo.<HttpData<PageBean<HomeBorrowGetTransrecordBean>>>post(HttpConfig.BASE_URL + HttpConfig.HOME_BORROW_GET_TRANSRECORD)
                .params("type", type)
                .params("pid", pid)
                .params("status", status)
                .params("p", p)
                .params("size", size);
    }

    /**
     * 理财币种列表
     *
     * @return
     */
    public PostRequest<HttpData<List<HomeLendLendCoinListBean>>> homeLendLendCoinList() {
        return OkGo.<HttpData<List<HomeLendLendCoinListBean>>>post(HttpConfig.BASE_URL + HttpConfig.HOME_LEND_LEND_COIN_LIST);
    }

    /**
     * 理财统计
     *
     * @param code 理财币种标识，如：BTC、ETH
     * @return
     */
    public PostRequest<HttpData<HomeLendBlend>> homeLendBlend(String code) {
        return OkGo.<HttpData<HomeLendBlend>>post(HttpConfig.BASE_URL + HttpConfig.HOME_LEND_BLEND)
                .params("code", code);
    }

    /**
     * 理财挂单
     *
     * @param code    理财币种标识，如：BTC、ETH
     * @param num     理财数量
     * @param rate    利率
     * @param days    周期(天)
     * @param is_auto 1自动放贷 0手动
     * @param tpwd    资金密码
     * @return
     */
    public PostRequest<HttpData> homeLendLendAdd(String code, String num, String rate, String days, String is_auto, String tpwd) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.HOME_LEND_LEND_ADD)
                .params("code", code)
                .params("num", num)
                .params("rate", rate)
                .params("days", days)
                .params("is_auto", is_auto)
                .params("tpwd", CommonUtil.getFiveMd5Value(tpwd));
    }

    /**
     * 理财赎回
     *
     * @param order_id 理财记录id
     * @return
     */
    public PostRequest<HttpData> homeLendPayBack(String order_id, String tpwd) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.HOME_LEND_PAY_BACK)
                .params("order_id", order_id)
                .params("tpwd", CommonUtil.getFiveMd5Value(tpwd))
                ;
    }

    /**
     * 理财记录
     *
     * @param status 1理财中 2已赎回
     * @param p      页码，默认1
     * @param size   页条数，默认10
     * @return
     */
    public PostRequest<HttpData<PageBean<HomeLendGetTransrecord>>> homeLendGetTransrecord(String status, String p, String size) {
        return OkGo.<HttpData<PageBean<HomeLendGetTransrecord>>>post(HttpConfig.BASE_URL + HttpConfig.HOME_LEND_GET_TRANSRECORD)
                .params("status", status)
                .params("p", p)
                .params("size", size);
    }


    public PostRequest<HttpData<TradeAccountBean>> tradeAccount() {
        return OkGo.<HttpData<TradeAccountBean>>post(HttpConfig.BASE_URL + HttpConfig.TRADE_ACCOUNT)

                .params("p", 1)
                .params("size", 100);
    }

    /**
     * 交易、理财账户币种列表
     *
     * @return
     */
    public PostRequest<HttpData<HomeQbwAccountList>> homeQbwAccountList() {
        return OkGo.<HttpData<HomeQbwAccountList>>post(HttpConfig.BASE_URL + HttpConfig.HOME_QBW_ACCOUNT_LIST);
    }

    /**
     * 抵押借贷统计
     *
     * @return
     */
    public PostRequest<HttpData<List<HomeBorrowTransTotal>>> homeBorrowTransTotal() {
        return OkGo.<HttpData<List<HomeBorrowTransTotal>>>post(HttpConfig.BASE_URL + HttpConfig.HOME_BORROW_TRANS_TOTAL);
    }

    public GetRequest<HttpData<PageBean<AssetBean>>> getAssetRecord(String pid, String type, String p, String size) {
        return OkGo.<HttpData<PageBean<AssetBean>>>get(HttpConfig.BASE_URL + HttpConfig.ASSET_RECORD)
                .params("type", type)
                .params("pid", pid)
                .params("p", p)
                .params("size", size)
                ;
    }


    /**
     * 可抵押币种列表
     *
     * @param type type=1 借钱 type=2借币
     * @return
     */
    public PostRequest<HttpData<List<HomeQbwCoinsList>>> homeQbwCoinsList(String type) {
        return OkGo.<HttpData<List<HomeQbwCoinsList>>>post(HttpConfig.BASE_URL + HttpConfig.HOME_QBW_COINS_LIST)
                .params("type", type);
    }

    /**
     * 抵押借贷补仓
     *
     * @param id   抵押记录id
     * @param code 抵押币标识，如BTC
     * @param num  补仓数量
     * @param pwd  资金密码
     */
    public PostRequest<HttpData> supply(String id, String code, String num, String pwd) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.FINAN_SUPPLY)
                .params("tran_id", id)
                .params("out_code", code)
                .params("num", num)
                .params("tpwd", CommonUtil.getFiveMd5Value(pwd))
                ;
    }

    /**
     * 抵押借款补仓页面
     *
     * @param code
     * @return
     */
    public PostRequest<HttpData<SupplyData>> getSupplyCode(String code) {
        return OkGo.<HttpData<SupplyData>>post(HttpConfig.BASE_URL + HttpConfig.FINAN_SUPPLY_DATA)
                .params("out_code", code)
                ;
    }

    public PostRequest<HttpData<RateBean>> getBorrowRate(String tran_id) {
        return OkGo.<HttpData<RateBean>>post(HttpConfig.BASE_URL + HttpConfig.FINAN_BORROW_RATE)
                .params("tran_id", tran_id)
                ;
    }

    public PostRequest<HttpData<RateBean>> getFinanceRate(String tran_id) {
        return OkGo.<HttpData<RateBean>>post(HttpConfig.BASE_URL + HttpConfig.FINAN_BORROW_RATE)
                .params("tran_id", tran_id)
                ;
    }

    public PostRequest<HttpData<List<String>>> getMorgageDay() {
        return OkGo.<HttpData<List<String>>>post(HttpConfig.BASE_URL + HttpConfig.MORGAGE_DAY)

                ;
    }
}